package j.framework.core;

import j.util.ConvertUtils;
import j.util.SpringBeans;
import j.util.StringUtils;

/**
 * User: jason
 * Date: 2014/11/6 14:23
 */
public final class JUtils {
    public static String formatGender(String gender) {
        if(StringUtils.isNullOrEmpty(gender)){
            return "未知";
        }else if(gender.equals("F")){
            return "男";
        }
        return "女";
    }

    public static <T> T newInstance(Class<T> clazz,String className){
        try {
            Object obj = Class.forName(className).newInstance();
            return (T)obj;
        }catch (Exception e){
            throw new RuntimeException("无法实例化"+className+"实例！");
        }
    }

    public static String formatBoolean(String inputStr) {
        if(StringUtils.isNotEmpty(inputStr)){
            if(ConvertUtils.toBoolean(inputStr)){
                return "是";
            }
        }
        return "否";
    }

    public static Object getBeanByClassName(String beanClassName){
        try {
            Class<?> clazz = Class.forName(beanClassName);
            return SpringBeans.getBean(clazz);
        }catch (ClassNotFoundException e){
            throw new RuntimeException("bean["+beanClassName+"]不存在，请与系统开发人员联系！");
        }
    }
}
